package soccerBet.project.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import soccerBet.project.contracts.EquipaContract;
import soccerBet.project.objects.*;
import soccerBet.project.utils.*;

public class ClassificacaoDAO {


	public Classificacao getClassificacao(Integer idEquipa) {

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		Classificacao classificacao = (Classificacao)  session.
		createQuery("select c from Classificacao as c join c.equipa as e where e.idEquipa = ?").setInteger(0, idEquipa).uniqueResult();
		
		
		session.close();
		
		return classificacao;


	}
   
  public List<Classificacao> getClassificacaoList(Integer idEpocaLiga) {

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		List<Classificacao> classList = (List<Classificacao> )     session.
		createQuery("select c from Classificacao as c join c.epocaLiga as el where el.idEpocaLiga = ? order by c.pontos desc").setInteger(0, idEpocaLiga).list();
		
		
		session.close();
		
		return classList;


	}
 

	
	public void insertToDB(Classificacao classificacao) {
		// TODO Auto-generated method stub
		
		Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
       
    	session.save(classificacao);

        //Commit the transaction
        session.getTransaction().commit();
        
    	
		session.close();
	}
	
	public void updateToDB(Classificacao classificacao) {
		// TODO Auto-generated method stub
		
		Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        
    	session.update(classificacao);

        //Commit the transaction
        session.getTransaction().commit();
        
    	
		session.close();
	}


	

}